clear all;
close all;
xk1=[1;-1];
c=5;a=3;
nu_1=0;nu_2=0;
T=0.001;
for k=1:1:10000
time(k)=k*T;
yd(k)=0;
if time(k)>=6
    dt(k)=0.5;
else 
    dt(k)=0;
end

tSpan=[0 T];

para1=[nu_1,nu_2];      % D/A
[tt,xx]=ode45('plant',tSpan,xk1,[],para1);
xk1=xx(length(xx),:);    % A/D
x1(k)=xk1(1);
x2(k)=xk1(2);

sigma=x2(k)+c*x1(k);
ut(k)=-1*(-2*x1(k)-x2(k)+exp(x1(k))+c*x2(k)+a*sign(sigma));

nu_1=ut(k);
nu_2=dt(k);
end

plot(time,x1,'k',time,yd,'r','linewidth',2);
xlabel('Time/s');ylabel('x1');
legend('x1','x1 estimation','measured x1');

figure(2);
plot(time,x2,'k','linewidth',2);
xlabel('Time/s');ylabel('Varying measurement delay time');

figure(3);
plot(time,ut,'k','linewidth',2);
xlabel('Time/s');ylabel('Varying measurement delay time');